  
  
$(document).ready(function(){
  
  //////////////////////////////
  //// Initialie ELFINDER //////
  $('#file_exp').elfinder({
        url : elfinderConnectorPath, // var set via php in a <script> block in default.ctp
        //url : '../libs/Elfinder1.2/connectors/php/connector.php', // doesn't work
        lang : 'en',
        //docked: true, // don't use 'docked' feature (which gives ability to undock) when using as modal
        height: 500  // height in pixels of the file manager (can also set it in the CSS)
  }); 
  
  ////////////////////////////////
  ///// MODAL OVERLAY ////////////
  $("a[rel='#file_exp_container']").overlay({
    
    effect:'apple',
    // custom top position
    top: 100,
    
    mask: {
      //color: '#fff',
      color: '#444',
      // load mask a little faster than the main overlay
      loadSpeed: 250,
      //loadSpeed: 550,
      opacity: 0.85,
      zIndex: 50
    },
    // give val of 'false' for modal dialog-type of overlays
    closeOnClick: false,
    fixed: false,  // 'false' means do not fix the overlay on the screen, but rather allow page scrolling
                  //  to also move the overlay
    speed: 450,  // speed (in miliseconds) of the loading
    zIndex: 100
        //    onLoad: function(content) {
        //    //onBeforeLoad: function(content) {
        //      //$('#exposeMask').siblings('img').css('opacity', 0);
        //      //$('#exposeMask').siblings('img').stop().animate({'opacity': 0}, 75);
        //    }
        //    onClose: function(content) {
        //			$('#exposeMask').siblings('img').css('opacity', 1.0);
        //		}
  }); // end .overlay() 


  ////////////////////////////////////////////////////////////
  ///// Handle FIJI/ImageJ launch-button clicks //////////////
  $('a.fiji').click(function(){
    
    // extract the Job id and Job Version id from custom html attributes on the page 
    var jobId =              $(this).attr('data-job_id');
    var jobVersionId =       $(this).attr('data-job_version_id');
    var isInputDataPreview = $(this).attr('data-is_input_data_preview');
    var jobGroupId         = $(this).attr('data-group_id');
    var jobDirName         = $(this).attr('data-job_dir_name');
    var projectionIndir    = $(this).attr('data-proj_indir');
    
    // Block the UI with a helpful message while the Ajax call processes
    $.blockUI({  
        message: '<h1 class="fijiAjaxWaitMsg">Just a moment while your image stacks are being built...</h1>',
        css: {width: '430px', padding: '20px', margin:'auto' }
    });
    
    // AJAX call.  Note that only vars that received a value above actually get passed.
    $.post(fijiAjaxLauncherUrl, // var set via php in a <script> block in default.ctp
           {'isInputDataPreview': isInputDataPreview, 'jobId': jobId, 'jobVersionId': jobVersionId,
            'jobGroupId': jobGroupId, 'jobDirName': jobDirName, 'projectionIndir': projectionIndir }, 
           handleFijiLaunchReady  // Callback func called after the Ajax request completes
          );
    
    return false; // prevent default action of the <a> element
  });
  // putting this inside the doc.ready() per: http://www.youtube.com/watch?v=dQ71psonQx0 @ 34:00
  // @param ajaxViewReturned   The ".ctp" view that renders after the Controller's method completes.
  //  (as of right now its called "fiji_ajax_launcher.ctp")
  //  (this 'result' gets passed automatically by jQuery)
  function handleFijiLaunchReady(ajaxViewReturned) {
    
    $('#Fiji_Div').html(ajaxViewReturned);
    
    // Display any flash messages as a notification box in the corner
    $('#AjaxMessages').purr({ // grabs #AjaxMessages element created in view 'fiji_ajax_launch.ctp'
      //isSticky: true,  // option to only remove the message by clicking close button
      fadeInSpeed:  700,
      fadeOutSpeed: 1400,
      removeTimer:  6200 // the time before the fadeout starts
    });
    
  }
  ////// end handling Fiji/ImageJ button clicks ////////////
  //////////////////////////////////////////////////////////

  //$(document).ajaxStart($.blockUI).ajaxStop($.unblockUI); // For all Ajax calls, use the default 'blockUI' and 'unblockUI'
  // unblock the UI when any Ajax activity stops 
  $(document).ajaxStop($.unblockUI); 

}); // end document ready func


//var Globals = {
//  addClickHandlerBlockUI : function( msgHtml ) {
//  //function addClickHandlerBlockUI( msgHtml ) {
//    var defaultMsgHtml = "<h1>Yo!!!!</h1>";
//    var _msgHtml = msgHtml ? msgHtml : defaultMsgHtml;
//
//     // Block the UI with a helpful message while the Ajax call processes
//    $.blockUI({  // TODO: figure out the path issue to enable using my 'busy.gif'
//      message: _msgHtml, 
//      css: { width: '400px', padding: '20px'  }
//    });
//  }
//}
